import Vue from 'vue'
import App from './App.vue'
import router from './router'
//导入axios
import axios from 'axios'
import qs from 'qs'

import './assets/i/iconfont.css'
import './assets/i/iconfont.js'


import VCharts from 'v-charts'

Vue.use(VCharts)
import VeLine from 'v-charts/lib/map.common'
Vue.component(VeLine.name, VeLine)


//在Vue对象添加了一个属性，以后访问axios-->this.$axios
Vue.prototype.$axios = axios
Vue.prototype.qs = qs
//引入ElememtUI
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import echarts from 'echarts'

Vue.use(ElementUI)
Vue.config.productionTip = false
Vue.prototype.$echarts = echarts

//引入vue-cropper图片裁剪工具
import VueCropper from 'vue-cropper'
Vue.use(VueCropper )


import store from './store'
import {initMenu} from './utils/power'


/*登录拦截*/
router.beforeEach((to, from, next) => {
        if (to.name == 'DLogin') {
            next();
            return;
        }
        var empName = JSON.parse(localStorage.getItem("user"));
        if (empName == null) {
            if (to.meta.requireAuth || to.name == null) {
                console.log(empName);
                console.log(to.meta.requireAuth);
                next({path: '/login'})
            } else {
                console.log(empName);
                next();
            }
        } else {
            initMenu(router, store);
            next();
        }

    }
)


Vue.prototype.print = (obj,type) => {
  type = type || "log";
  const log = JSON.parse(JSON.stringify(obj));
  console[type](log)
}
new Vue({
  render: h => h(App),
  store,
  router
}).$mount('#app')
